<template>
    
    <el-drawer
        ref="drawerRef"
        class="bg-page"
        v-model="drawerOpen"
        :title="`协同工单号: ${formData.cooperateOrderNo}`"
        direction="rtl"
        :before-close="closeDrawer"
        size="80%"
    >
        
        <el-scrollbar>
            
            
            <el-form ref="formRef" class="pl-3" :model="formData" label-width="110px" inline>
                <el-steps :active="afterSaleOrderStatus.currentStatus" class="px-10 p-2 mb-3 rounded-t-lg  !bg-white "
                          finish-status="finish">
                    
                    
                    <el-step v-for="(item,index) in afterSaleOrderStatus.statusList" class="mt-4">
                        <template v-slot:title>
                            <div class="text-xs"> {{ item }}</div>
                        
                        
                        </template>
                        
                        <template v-slot:icon>
                            <icon :size="11" name="el-icon-CircleCheckFilled"/>
                        </template>
                    </el-step>
                
                
                </el-steps>
                
                <!--                售后工单信息-->
                <el-card class="!border-none  " shadow="never">
                    <div class="flex ">
                        <el-tabs class="flex flex-1 items-center" tab-position="left">
                            <el-tab-pane class="text-2xl font-medium" disabled>售后工单信息</el-tab-pane>
                        </el-tabs>
                        
                        
                        <el-button
                            v-show="!isExpansion"
                            @click="isExpansion = !isExpansion"
                            type="primary"
                            link
                        >
                            展开
                        </el-button>
                        
                        <el-button
                            v-show="isExpansion"
                            @click="isExpansion = !isExpansion"
                            type="primary"
                            link
                        >
                            收起
                        </el-button>
                    </div>
                
                
                </el-card>
                
                <div v-show="isExpansion">
                    <!--                基本信息-->
                    <el-card class="!border-none flex flex-1  justify-center items-center" shadow="never">
                        <div class=" text-lg	 mb-4">
                            基本信息
                        </div>
                        
                        <div class=" w-[800px]  ">
                            <div class="pl-3 grid grid-cols-2 gap-0">
                                <div>
                                    <el-form-item label="工单类型 :"
                                                  prop="afterSaleOrderDetail.afterSaleOrderType">
                                        
                                        <p v-for="item in afterSaleOrderConfig.afterSaleOrderType"
                                           v-show="item.code ===formData.afterSaleOrderDetail?.afterSaleOrderType "
                                           class="text-tx-regular">
                                            {{ item.name }}
                                        </p>
                                    
                                    </el-form-item>
                                </div>
                                
                                
                                <div>
                                    <el-form-item label="来源 :" prop="source">
                                        <p v-for="item in afterSaleOrderConfig.orderSourceConfig"
                                           v-show="item.name ===formData.afterSaleOrderDetail?.source "
                                           class="text-tx-regular">
                                            
                                            {{ item.value }}
                                        </p>
                                    
                                    
                                    </el-form-item>
                                </div>
                                
                                
                                <div>
                                    <el-form-item label="渠道 :" prop="channel">
                                        
                                        <p v-for="item in afterSaleOrderConfig.orderChannelConfig "
                                           v-show="item.name ===formData.afterSaleOrderDetail?.channel "
                                           class="text-tx-regular">
                                            
                                            {{ item.value }}
                                        </p>
                                    
                                    
                                    </el-form-item>
                                </div>
                                
                                
                                <div>
                                    <el-form-item label="店铺 :" prop="shopName">
                                        <p v-for="item in shopNameList "
                                           v-show="item.name ===formData.afterSaleOrderDetail?.shopName "
                                           class="text-tx-regular">
                                            
                                            {{ item.value }}
                                        </p>
                                    </el-form-item>
                                </div>
                            
                            </div>
                        
                        </div>
                    </el-card>
                    
                    <!--                订单信息-->
                    <el-card class="!border-none flex flex-1 items-center justify-center " shadow="never">
                        <div class=" text-lg	 mb-4">订单信息</div>
                        <div class=" w-[800px] ">
                            
                            <div class="pl-3  grid grid-cols-2 gap-0">
                                <div>
                                    <el-form-item label="订单号 :" prop="afterSaleOrderDetail.orderNumber">
                                        <p class="text-tx-regular">
                                            {{ formData.afterSaleOrderDetail?.orderNumber }}
                                        </p>
                                    
                                    
                                    </el-form-item>
                                </div>
                                
                                
                                <div>
                                    <el-form-item label="原因类别 :" prop="afterSaleOrderDetail.reason">
                                        
                                        <p v-for="item in afterSaleOrderConfig.orderCauseConfig"
                                           v-show="item.name ===formData.afterSaleOrderDetail?.reason "
                                           class="text-tx-regular">
                                            {{ item.value }}
                                        </p>
                                    
                                    </el-form-item>
                                </div>
                            
                            </div>
                        
                        </div>
                    </el-card>
                    
                    <!--                寄回物流信息-->
                    <el-card class="!border-none flex flex-1 items-center justify-center " shadow="never">
                        <div class=" text-lg	 mb-4">寄回物流信息</div>
                        
                        <div class=" w-[800px]  pl-8">
                            <div class="pl-3  grid grid-cols-2 gap-0">
                                <div>
                                    <el-form-item label="寄回物流公司 :"
                                                  prop="afterSaleOrderDetail.logisticNumber">
                                        <p class="text-tx-regular">
                                            {{ formData.afterSaleOrderDetail?.logisticNumber }}
                                        </p>
                                    
                                    
                                    </el-form-item>
                                </div>
                                
                                <div>
                                    <el-form-item label="寄回物流单号 :"
                                                  prop="afterSaleOrderDetail.logisticCompany">
                                        <p class="text-tx-regular">
                                            {{ formData.afterSaleOrderDetail?.logisticCompany }}
                                        </p>
                                    </el-form-item>
                                </div>
                            
                            </div>
                        
                        </div>
                    </el-card>
                    
                    <!--                    工单描述-->
                    <el-card class="!border-none flex flex-1 items-center justify-center " shadow="never">
                        <div class=" w-[800px]">
                            <div class=" text-lg	 mb-4">工单描述</div>
                            
                            
                            <div class="pl-3  grid grid-cols-1 ">
                                <div>
                                    <el-form-item label="描述 :" prop="afterSaleOrderDetail.description"
                                                  class="w-full">
                                        <p class="text-tx-regular break-words w-9/12">
                                            {{ formData.afterSaleOrderDetail?.description }}
                                        </p>
                                    </el-form-item>
                                </div>
                            
                            
                            </div>
                        
                        </div>
                    </el-card>
                
                </div>
                
                
                <!--                协同详情-->
                <el-card class="!border-none   mt-4 " shadow="never">
                    <div class="flex">
                        <el-tabs class="items-center flex flex-1" tab-position="left">
                            <el-tab-pane class="text-2xl font-medium" disabled>详情</el-tab-pane>
                        </el-tabs>
                    </div>
                
                
                </el-card>
                <div>
                    <!--                基本信息-->
                    <el-card class="!border-none flex flex-1  justify-center items-center" shadow="never">
                        <div class=" text-lg	 mb-4">
                            基本信息
                        </div>
                        
                        <div class=" w-[800px]  ">
                            <div class="pl-3 grid grid-cols-2 gap-0">
                                <div>
                                    <el-form-item label="协同类型 :">
                                        <p v-for="item in afterSaleOrderConfig.cooperateOrderType"
                                           v-show="item.code ===formData.type "
                                           class="text-tx-regular">
                                            {{ item.name }}
                                        </p>
                                    </el-form-item>
                                </div>
                                
                                
                                <div>
                                    <el-form-item label="提交人 :">
                                        <p class="text-tx-regular">
                                            {{ formData.createPerson }}
                                        </p>
                                    </el-form-item>
                                </div>
                                
                                
                                <div>
                                    <el-form-item label="用户名称 :">
                                        <p class="text-tx-regular">
                                            {{ formData.afterSaleOrderDetail?.userName }}
                                        </p>
                                    </el-form-item>
                                </div>
                                
                                
                                <div>
                                    <el-form-item label="用户电话 :">
                                        <p class="text-tx-regular">
                                            {{ formData.afterSaleOrderDetail?.userPhone }}
                                        </p>
                                    </el-form-item>
                                </div>
                                
                                <div>
                                    <el-form-item label="当前受理人 :" prop="shopName">
                                        <p class="text-tx-regular">
                                            {{ formData.acceptPerson }}
                                        </p>
                                    </el-form-item>
                                </div>
                                
                                <div>
                                    <el-form-item label="介入人 :" prop="shopName">
                                        <p class="text-tx-regular">
                                            {{ formData.intervenePerson }}
                                        </p>
                                    </el-form-item>
                                </div>
                            </div>
                        
                        </div>
                    </el-card>
                    
                    <el-card class="!border-none flex flex-1 items-center justify-center " shadow="never">
                        <div class=" w-[800px]">
                            <div class=" text-lg	 mb-4">协同描述</div>
                            
                            
                            <div class="pl-3  grid grid-cols-1 ">
                                <div>
                                    <el-form-item label="描述 :" prop="afterSaleOrderDetail.description"
                                                  class="w-full">
                                        <p class="text-tx-regular break-words w-9/12">
                                            {{ formData.description }}
                                        </p>
                                    </el-form-item>
                                </div>
                            
                            
                            </div>
                        
                        </div>
                    </el-card>
                    
                    <!--                    拒收物流信息-->
                    <el-card class="!border-none flex flex-1 items-center justify-center " shadow="never"
                    >
                        <div class=" text-lg	 mb-4">拒收物流信息</div>
                        
                        <div class=" w-[800px]  pl-8">
                            <div class="pl-3  grid grid-cols-2 gap-0">
                                <div>
                                    <el-form-item label="收件人名称 :" prop="afterSaleAddress.userName">
                                        <p class="text-tx-regular">
                                            {{ formData.afterSaleAddress?.userName }}
                                        </p>
                                    
                                    
                                    </el-form-item>
                                </div>
                                
                                <div>
                                    <el-form-item label="收件人电话 :" prop="afterSaleAddress.userPhone">
                                        <p class="text-tx-regular">
                                            {{ formData.afterSaleAddress?.userPhone }}
                                        </p>
                                    </el-form-item>
                                </div>
                                
                                
                                <div>
                                    <el-form-item label="省市区: " prop="afterSaleAddress.addressInfoEnum">
                                        <p class="text-tx-regular">
                                            {{ formData.afterSaleAddress?.addressInfoEnum.join("") }}
                                        </p>
                                    </el-form-item>
                                
                                </div>
                                
                                <div>
                                    <el-form-item label="详细地址" prop="addressInfo.address">
                                        <p class="text-tx-regular">
                                            {{ formData.afterSaleAddress?.addressFull }}
                                        </p>
                                    </el-form-item>
                                </div>
                            
                            
                            </div>
                        
                        </div>
                    </el-card>
                
                </div>
                
                
                <!--                表单数据-->
                <el-card class="!border-none      " shadow="never">
                    
                    <div v-if="showResolveButton">
                        <el-button type="primary" @click="handleCreateFeedbackRecord">
                            <template #icon>
                                <icon name="el-icon-Plus"/>
                            </template>
                            电联待反馈
                        </el-button>
                    </div>
                    
                    
                    <el-table
                        ref="tableRef"
                        class="mt-3 ml-16   -ml-1 mb-20 rounded-t-lg"
                        size="default"
                        :data="formData.cooperateLine"
                    >
                        
                        <el-table-column type="index" fixed label="行号" width="70"/>
                        <el-table-column label="协同物料状态" fixed prop="status" min-width="120">
                            <template #default="{ row }">
                                <ScSignSvgRound
                                    v-for="(item,index)   in afterSaleOrderConfig.cooperateOrderLineStatus"
                                    v-show=" row.status === item.code"
                                    :key=index
                                    :background="item.type"
                                    :value="item.name"/>
                            </template>
                        
                        
                        </el-table-column>
                        
                        <el-table-column label="物料名称" prop="itemName" min-width="120"/>
                        <el-table-column label="物料编码" prop="itemCode" min-width="120"/>
                        
                        <el-table-column label="69码" prop="batch" min-width="120"/>
                        
                        <el-table-column label="SN" prop="sn" min-width="150"/>
                        
                        <el-table-column label="入库仓" prop="warehouse" min-width="120"
                                         :formatter="formatterManager.formatterWarehouse"/>
                        
                        
                        <el-table-column label="错误类型" prop="checkFault" min-width="150"/>
                        
                        
                        <el-table-column label="质检物料描述" prop="description" min-width="270"
                                         :show-overflow-tooltip="true"/>
                        
                        
                        <el-table-column label="处理方式" prop="resolveWay" fixed="right" min-width="190"
                                         v-if="showResolveButton">
                            <template #default="{row}">
                                
                                <el-select placeholder="请选中处理方式" v-model="row.resolveWay"
                                           :disabled="row.isDisabled"
                                           @change="handleChanger(row) ">
                                    <el-option v-for="item in getCooperateProcessMode(row)"
                                               :label="item.value"
                                               :value="item.name"/>
                                </el-select>
                            </template>
                        </el-table-column>
                        
                        <el-table-column label="操作" fixed="right" min-width="120" v-if="showResolveButton">
                            <template #default="{row}">
                                
                                <el-button
                                    v-if="!row.isDisabled"
                                    @click="resolveCurrentLine(row)"
                                    type="primary"
                                    link
                                >
                                    解决
                                </el-button>
                                
                                
                                <el-button
                                    v-if="!row.isDisabled"
                                    @click="row.isDisabled=true"
                                    link
                                >
                                    固定
                                </el-button>
                                
                                <el-button
                                    v-if="row.isDisabled"
                                    @click="row.isDisabled=false"
                                    link
                                >
                                    编辑
                                </el-button>
                            
                            
                            </template>
                        </el-table-column>
                    </el-table>
                
                </el-card>
                <!--                跟踪记录-->
                <el-card class="!border-none   mt-4 " shadow="never">
                    <div class="flex ">
                        <el-tabs class="flex flex-1 items-center" tab-position="left">
                            <el-tab-pane class="text-2xl font-medium" disabled>跟踪记录</el-tab-pane>
                        </el-tabs>
                        
                        
                        <el-button
                            v-show="!isExpansionRecord"
                            @click="isExpansionRecord = !isExpansionRecord"
                            type="primary"
                            link
                        >
                            展开
                        </el-button>
                        
                        <el-button
                            v-show="isExpansionRecord"
                            @click="isExpansionRecord = !isExpansionRecord"
                            type="primary"
                            link
                        >
                            收起
                        </el-button>
                    </div>
                
                </el-card>
                
                <el-card class="!border-none " shadow="never" v-if="isExpansionRecord">
                    <div class="ml-8 mt-1">
                        <el-timeline>
                            
                            <el-timeline-item v-for="item in formData.cooperateOrderRecord"
                                              :timestamp="item.formatCreateTime" placement="top">
                                <el-card>
                                    <h4>{{ item.description }}</h4>
                                    <div class="flex justify-end">
                                        <p>{{ item.optPerson }} : {{ item.formatCreateTime }}</p>
                                    </div>
                                
                                </el-card>
                            </el-timeline-item>
                        
                        </el-timeline>
                    </div>
                </el-card>
                
                
                <el-card class="!border-none  flex justify-center mt-2 " shadow="never"
                         v-if="formData.status===CooperateOrderStatusEnum.WAIT_ACCEPTANCE">
                    <el-button
                        @click="acceptCooperateOrder"
                        type="primary"
                    
                    >
                        受理
                    </el-button>
                </el-card>
            </el-form>
        
        
        </el-scrollbar>
        
        <template v-if="showCooperateResolve" #footer>
            <el-card class="!border-none flex flex-1 items-center justify-center " shadow="never">
                <el-button type="primary" @click="handleSubmit">工单处理完成</el-button>
            </el-card>
        </template>
    
    </el-drawer>
    
    
    <EditLine ref="editLineRef" @confirm="handleEditLineConfirm" @close="handleEditLineClose" v-if="showEditLineRef"/>
    <EditAddress ref="editAddressRef" @confirm="handleEditAddressConfirm" v-if="showEditAddressRef"/>

</template>

<script lang='ts' setup>

import EditLine from './edit-line.vue'
import EditAddress from './edit-address.vue'
import CooperateOrderLineDTO from "@/api/afterSale/cooperate/dto/CooperateOrderLineDTO";
import feedback from "@/utils/feedback";
import {
    acceptCurrentCooperateOrder,
    createCooperateOrderRecord, getCooperateOrderInfo,
    getCooperateOrderStatusManager, resolveCooperate
} from "@/api/afterSale/cooperate/AfterSaleCooperateOrderController";
import {useAfterSaleEnumManager} from "@/manager/base/AfterSaleEnumManager";
import useUserStore from "@/base/stores/modules/user";
import {useFormatterManager} from "@/manager/base/FormatterManager";
import AfterSaleStatusInfoDTO from "@/api/afterSale/order/dto/AfterSaleStatusInfoDTO";
import CooperateOrderInfoDTO from "@/api/afterSale/cooperate/dto/CooperateOrderInfoDTO";
import {UnwrapNestedRefs} from "@vue/reactivity";
import CooperateOrderLineSolveRequest from "@/api/afterSale/cooperate/request/CooperateOrderLineSolveRequest";
import IdRequest from "@/api/baisc/IdRequest";
import {CooperateLineStatusEnum} from "@/config/enums/aftersale/CooperateLineStatusEnum";
import {CooperateOrderStatusEnum} from "@/config/enums/aftersale/CooperateOrderStatusEnum";
import CooperateOrderRecordRequest from "@/api/afterSale/cooperate/request/CooperateOrderRecordRequest";
import {AfterSaleAddressDTO} from "@/api/afterSale/order/dto/AfterSaleAddressDTO";
import CooperateOrderSolveRequest from "@/api/afterSale/cooperate/request/CooperateOrderSolveRequest";
import {resolveCooperateLine} from "@/api/afterSale/cooperate/AfterSaleCooperateOrderLinerController";
import {CooperateProcessType} from "@/config/enums/aftersale/CooperateProcessType";
import {addAfterSaleOrderRecipientAddress} from "@/api/afterSale/order/AfterSaleOrderController";


let afterSaleOrderConfig = useAfterSaleEnumManager();
let formatterManager = useFormatterManager(afterSaleOrderConfig);


const editLineRef = shallowRef(EditLine)
const editAddressRef = shallowRef(EditAddress)
let userStore = useUserStore();


// 是否显示物料信息
const showEditLineRef = ref(false)
const showEditAddressRef = ref(false)

const isExpansion = ref(false)
const isExpansionRecord = ref(true)


let afterSaleOrderStatus: AfterSaleStatusInfoDTO = reactive(new AfterSaleStatusInfoDTO())
let formData: UnwrapNestedRefs<CooperateOrderInfoDTO> = reactive(new CooperateOrderInfoDTO())
let cacheRequestDate: UnwrapNestedRefs<CooperateOrderLineSolveRequest> = reactive(new CooperateOrderLineSolveRequest())
let idRequest = reactive(new IdRequest())


const drawerOpen = ref(false)


/**
 * 处理值变化
 *
 * @author 徐寿春
 * 2023/4/14 17:17
 */
async function handleChanger(val: CooperateOrderLineDTO) {
    cacheRequestDate.cooperateOrderLineId = val.cooperateOrderLineId
    cacheRequestDate.resolveWay = val.resolveWay
    
    switch (val.resolveWay) {
        // 处理弹窗 应设置 CORRECT
        case CooperateProcessType.POPALLUP:
            
            showEditLineRef.value = true
            await nextTick()
            editLineRef.value?.open(val)
            break
        
        
        // 处理退回
        case CooperateProcessType.RETURN:
            showEditAddressRef.value = true
            await nextTick()
            editAddressRef.value?.open(formData.afterSaleOrderId)
            break
        
        case CooperateProcessType.CHECKRETEST:
            if (!!cacheRequestDate.batch && cacheRequestDate.itemName) {
                val.itemCode = cacheRequestDate.itemCode
                val.itemName = cacheRequestDate.itemName
                val.batch = cacheRequestDate.batch
                val.sn = cacheRequestDate.sn
            }
            
            break
    }
    
}


// ------------------------------------------------ ** 协同受理 ** ----------------------------------------------

/**
 * 解决当前物料
 *
 * @author 徐寿春
 * 2023/4/14 22:07
 */
function resolveCurrentLine(row: CooperateOrderLineDTO) {
    
    if (row.resolveWay == null) {
        feedback.notifyWarning("处理方式不可为空")
        return
    }
    
    let cooperateOrderLineSolve = new CooperateOrderLineSolveRequest();
    for (let key in cooperateOrderLineSolve) {
        //@ts-ignore
        cooperateOrderLineSolve[key] = row[key]
    }
    
    
    resolveCooperateLine(cooperateOrderLineSolve).then(() => {
        feedback.notifySuccess("解决成功")
        getDataInfo(idRequest)
    })
    
}


/**
 * 整体协同工单解决
 *
 * @author 徐寿春
 * 2023/4/15 19:46
 */
function handleSubmit() {
    let cooperateOrderSolveRequest = new CooperateOrderSolveRequest();
    
    cooperateOrderSolveRequest.cooperateLine = formData.cooperateLine
    cooperateOrderSolveRequest.afterSaleOrderId = formData.afterSaleOrderId
    cooperateOrderSolveRequest.cooperateOrderId = formData.cooperateOrderId
    resolveCooperate(cooperateOrderSolveRequest).then(() => {
        drawerOpen.value = false
        closeDrawer()
    })
    
    
}


/**
 *
 * 受理当前协同工单
 *
 * @author 徐寿春
 * 2023/4/17 10:16
 */
function acceptCooperateOrder() {
    acceptCurrentCooperateOrder(idRequest).then(() => {
        getDataInfo(idRequest)
        getCooperateOrderStatusManager(idRequest).then(spoons => {
            for (let formDataKey in afterSaleOrderStatus) {
                //@ts-ignore
                afterSaleOrderStatus[formDataKey] = spoons[formDataKey]
            }
            
        })
        feedback.notifySuccess("受理成功")
    })
    
}


// ------------------------------------------------ ** 处理物料弹窗 ** ----------------------------------------------


/**
 * 处理弹窗物料处理结果
 *
 * @author 徐寿春
 * 2023/4/9 22:41
 */
function handleEditLineConfirm(val: CooperateOrderLineDTO) {
    let find = formData.cooperateLine?.find(item => item.cooperateOrderLineId == val.cooperateOrderLineId);
    // 原来数据缓存
    for (let key in cacheRequestDate) {
        //@ts-ignore
        cacheRequestDate[key] = find[key]
    }
    
    // 新数据赋值
    if (!!find) {
        find.itemCode = val.itemCode
        find.itemName = val.itemName
        find.batch = val.batch
        find.sn = val.sn
    }
}

/**
 * 处理弹窗地址处理结果
 *
 * @author 徐寿春
 * 2023/4/9 22:41
 */
function handleEditAddressConfirm(val: AfterSaleAddressDTO) {
    val.afterSaleOrderId = formData.afterSaleOrderId
    addAfterSaleOrderRecipientAddress(val).then(() => {
        formData.afterSaleAddress = val
        let arr = [val.economize,val.city,val.county,val.address]
        formData.afterSaleAddress.addressFull =arr.join("")
        feedback.notifySuccess("拒收地址确认成功")
        
    })
}

/**
 * 处理物料关闭
 *
 * @author 徐寿春
 * 2023/5/5 17:10
 */
function handleEditLineClose(val: CooperateOrderLineDTO) {
    let find = formData.cooperateLine?.find(item => item.cooperateOrderLineId == val.cooperateOrderLineId);
    if (!!find) {
        find.resolveWay = null
    }
    showEditLineRef.value = false
}

// ------------------------------------------------ ** 反馈记录 ** ----------------------------------------------

/**
 * 反馈记录
 *
 * @author 徐寿春
 * 2023/4/9 14:58
 */
function handleCreateFeedbackRecord() {
    feedback.prompt("请简单描述外呼遇到待问题", "反馈记录").then(item => {
        
        
        let cooperateOrderRecordRequest = new CooperateOrderRecordRequest();
        cooperateOrderRecordRequest.description = item.value?.trim()
        cooperateOrderRecordRequest.cooperateOrderId = formData.cooperateOrderId
        
        createCooperateOrderRecord(cooperateOrderRecordRequest).then(() => {
            getDataInfo(idRequest)
            feedback.notifySuccess("添加反馈记录成功")
        })
    }).catch(() => {
    })
    
}


// ------------------------------------------------ ** 基础 ** ----------------------------------------------

/**
 *  计算店铺信息
 *
 * @author 徐寿春
 * 2023/4/14 15:45
 */
const shopNameList = computed(() => {
    return formatterManager.computeFormatterShop(formData.afterSaleOrderDetail?.channel)
})


/**
 * 协同处理方式
 *
 * @author 徐寿春
 * 2023/4/14 16:55
 */
function getCooperateProcessMode(row: any) {
    return afterSaleOrderConfig.cooperateProcessMode.find(item => item.value === row.checkFault)?.children;
}


/**
 *  获取data数据
 *
 * @author 徐寿春
 * 2023/4/14 17:49
 */
function getDataInfo(id: IdRequest) {
    getCooperateOrderInfo(id).then(spoons => {
        for (let formDataKey in formData) {
            //@ts-ignore
            formData[formDataKey] = spoons[formDataKey]
        }
        
        formData.cooperateLine?.forEach(item => {
            if (item.status == CooperateLineStatusEnum.RESOLVED) {
                item.isDisabled = true
            }
            if (item.status === CooperateLineStatusEnum.WAIT_PROCESSING) {
                item.resolveWay = null
            }
        })
        
    })
}


/**
 * 打开协同弹窗
 */
async function open(id: number) {
    idRequest.id = id
    await getDataInfo(idRequest)
    await getCooperateOrderStatusManager({id}).then(spoons => {
        
        for (let formDataKey in afterSaleOrderStatus) {
            //@ts-ignore
            afterSaleOrderStatus[formDataKey] = spoons[formDataKey]
        }
        
    })
    
    drawerOpen.value = true
}

const emit = defineEmits(['close'])


// 解决操作按钮
const showResolveButton = computed(() => {
    if (formData.status == CooperateOrderStatusEnum.COMPLETED) {
        return false
    }
    return userStore.userInfo.user.username === formData.acceptPerson || userStore.userInfo.username === formData.intervenePerson;
})


// 系统解决按钮
const showCooperateResolve = computed(() => {
    if (formData.status == CooperateOrderStatusEnum.COMPLETED) {
        return false
    }
    
    return formData.cooperateLine?.filter(item => item.status != CooperateLineStatusEnum.RESOLVED).length == 0
})


/**
 * 关闭当前Drawer
 */
function closeDrawer() {
    emit('close')
}

defineExpose({
    open
})

</script>

